#ifndef __DRV_HAL_KEY_H_
#define __DRV_HAL_KEY_H_
#include "board.h"

#define _HAL_KEY0_PIN              CONS2(GPIO_PIN_,BOARD_CONFIG_HAL_KEY0_NUM)
#define _HAL_KEY1_PIN              CONS2(GPIO_PIN_,BOARD_CONFIG_HAL_KEY1_NUM)
#define _HAL_KEY2_PIN              CONS2(GPIO_PIN_,BOARD_CONFIG_HAL_KEY2_NUM)
#define _HAL_KEY3_PIN              CONS2(GPIO_PIN_,BOARD_CONFIG_HAL_KEY3_NUM)

#define _HAL_KEY0_PORT             CONS2(GPIO,BOARD_CONFIG_HAL_KEY0_PORT)
#define _HAL_KEY1_PORT             CONS2(GPIO,BOARD_CONFIG_HAL_KEY1_PORT)
#define _HAL_KEY2_PORT             CONS2(GPIO,BOARD_CONFIG_HAL_KEY2_PORT)
#define _HAL_KEY3_PORT             CONS2(GPIO,BOARD_CONFIG_HAL_KEY3_PORT)

#define _HAL_KEY0_RCC              CONS3(__HAL_RCC_GPIO,BOARD_CONFIG_HAL_KEY0_PORT,_CLK_ENABLE)
#define _HAL_KEY1_RCC              CONS3(__HAL_RCC_GPIO,BOARD_CONFIG_HAL_KEY1_PORT,_CLK_ENABLE)
#define _HAL_KEY2_RCC              CONS3(__HAL_RCC_GPIO,BOARD_CONFIG_HAL_KEY2_PORT,_CLK_ENABLE)
#define _HAL_KEY3_RCC              CONS3(__HAL_RCC_GPIO,BOARD_CONFIG_HAL_KEY3_PORT,_CLK_ENABLE)

#if defined(BOARD_CONFIG_HAL_KEY0_PORT) && defined(BOARD_CONFIG_HAL_KEY0_ACTIVATE)
  #define BORAD_HAL_KEY0                CONS3(P,BOARD_CONFIG_HAL_KEY0_PORT,in(BOARD_CONFIG_HAL_KEY0_NUM))
#else
  #define BOARD_CONFIG_HAL_KEY0_ACTIVATE  0
  #define BORAD_HAL_KEY0                (!BOARD_CONFIG_HAL_KEY0_ACTIVATE)
#endif

#if defined(BOARD_CONFIG_HAL_KEY1_PORT) && defined(BOARD_CONFIG_HAL_KEY1_ACTIVATE)
  #define BORAD_HAL_KEY1                CONS3(P,BOARD_CONFIG_HAL_KEY1_PORT,in(BOARD_CONFIG_HAL_KEY1_NUM))
#else
  #define BOARD_CONFIG_HAL_KEY1_ACTIVATE  0
  #define BORAD_HAL_KEY1                (!BOARD_CONFIG_HAL_KEY1_ACTIVATE)
#endif

#if defined(BOARD_CONFIG_HAL_KEY2_PORT) && defined(BOARD_CONFIG_HAL_KEY2_ACTIVATE)
  #define BORAD_HAL_KEY2                CONS3(P,BOARD_CONFIG_HAL_KEY2_PORT,in(BOARD_CONFIG_HAL_KEY2_NUM))
#else
  #define BOARD_CONFIG_HAL_KEY2_ACTIVATE  0
  #define BORAD_HAL_KEY2                (!BOARD_CONFIG_HAL_KEY2_ACTIVATE)
#endif

#if defined(BOARD_CONFIG_HAL_KEY3_PORT) && defined(BOARD_CONFIG_HAL_KEY3_ACTIVATE)
  #define BORAD_HAL_KEY3                CONS3(P,BOARD_CONFIG_HAL_KEY3_PORT,in(BOARD_CONFIG_HAL_KEY3_NUM))
#else
  #define BOARD_CONFIG_HAL_KEY3_ACTIVATE  0
  #define BORAD_HAL_KEY3                (!BOARD_CONFIG_HAL_KEY3_ACTIVATE)
#endif

#define K0_PREESED            0x01
#define K1_PREESED            0x02
#define K2_PREESED            0x04
#define K3_PREESED            0x08

#define delay_ms              rt_thread_mdelay

void key_pin_init(void);
unsigned char key_getState(void);
u8 KEY_Scan(u8 mode);

#endif // __DRV_HAL_KEY_H_
